package de.tub.bazinga.highscore;

import processing.core.PApplet;
import de.tub.bazinga.object.Color;
import de.tub.bazinga.object.interf.Drawable;

public class Score implements Drawable {

	// fields
	private final int points;
	private final int position;
	private float x;
	private float y;
	private final Color color;

	// drawable
	private static final int TEXT_SIZE = 50;

	public Score(int points, int position, Color color, int width, int height) {
		this.points = points;
		this.position = position;
		this.color = color;

		generateCoordinates(position < 10 ? position : 10, width, height);
	}

	private void generateCoordinates(int position, int width, int height) {
		this.x = ((position % 2 == 0)) ? width / 2 : 20;
		this.y = (position - 1) * (height / 13) + 20 + TEXT_SIZE;
	}

	public int getPoints() {
		return points;
	}

	public int getPosition() {
		return position;
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	public Color getColor() {
		return color;
	}

	@Override
	public void draw(PApplet window) {
		if (color == null) {
			window.fill(245);
		} else {
			window.fill(color.getR(), color.getG(), color.getB());
		}
		window.textSize(TEXT_SIZE);
		window.text(position + ".", x, y);
		window.text(points, x + TEXT_SIZE * 2, y);

	}
}
